<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- 
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License. 
-->
<html>
<head>
    <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css">
    <style type="text/css">
        .dp-highlighter {
            width:95% !important;
        }
    </style>
    <style type="text/css">
        .footer {
            background-image:      url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif');
            background-repeat:     repeat-x;
            background-position:   left top;
            padding-top:           4px;
            color:                 #666;
        }
    </style>
    <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' />
    <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' />
    <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script>
    <script type="text/javascript">
        SyntaxHighlighter.defaults['toolbar'] = false;
        SyntaxHighlighter.all();
    </script>
    <script type="text/javascript" language="javascript">
        var hide = null;
        var show = null;
        var children = null;

        function init() {
            /* Search form initialization */
            var form = document.forms['search'];
            if (form != null) {
                form.elements['domains'].value = location.hostname;
                form.elements['sitesearch'].value = location.hostname;
            }

            /* Children initialization */
            hide = document.getElementById('hide');
            show = document.getElementById('show');
            children = document.all != null ?
                    document.all['children'] :
                    document.getElementById('children');
            if (children != null) {
                children.style.display = 'none';
                show.style.display = 'inline';
                hide.style.display = 'none';
            }
        }

        function showChildren() {
            children.style.display = 'block';
            show.style.display = 'none';
            hide.style.display = 'inline';
        }

        function hideChildren() {
            children.style.display = 'none';
            show.style.display = 'inline';
            hide.style.display = 'none';
        }
    </script>
    <title>Portlet Plugin</title>
</head>
<body onload="init()">
<table border="0" cellpadding="2" cellspacing="0" width="100%">
    <tr class="topBar">
        <td align="left" valign="middle" class="topBarDiv" align="left" nowrap>
            &nbsp;<a href="home.html">Home</a>&nbsp;&gt;&nbsp;<a href="guides.html">Guides</a>&nbsp;&gt;&nbsp;<a href="plugin-developers-guide.html">Plugin Developers Guide</a>&nbsp;&gt;&nbsp;<a href="portlet-plugin.html">Portlet Plugin</a>
        </td>
        <td align="right" valign="middle" nowrap>
            <form name="search" action="https://www.google.com/search" method="get">
                <input type="hidden" name="ie" value="UTF-8" />
                <input type="hidden" name="oe" value="UTF-8" />
                <input type="hidden" name="domains" value="" />
                <input type="hidden" name="sitesearch" value="" />
                <input type="text" name="q" maxlength="255" value="" />
                <input type="submit" name="btnG" value="Google Search" />
            </form>
        </td>
    </tr>
</table>

<div id="PageContent">
    <div class="pageheader" style="padding: 6px 0px 0px 0px;">
        <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
        <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
        <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div>
        <div style="margin: 0px 10px 8px 10px"  class="pagetitle">Portlet Plugin</div>

        <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=74033">
                <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=74033">Edit Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">
                <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a>
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=74033">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=74033">Add Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=74033">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add News"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=74033">Add News</a>
        </div>
    </div>

    <div class="pagecontent">
        <div class="wiki-content">
            <div id="ConfluenceContent"><h1 id="PortletPlugin-Documentation">Documentation</h1><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p><strong>The Portlet Plugin</strong>is used for developing JSR286 portlets using Struts 2<strong>.</strong></p></div></div><h2 id="PortletPlugin-portlet-class">portlet-class</h2><p>To use the Struts 2 Portlet framework, use <strong><em>org.apache.struts2.portlet.dispatcher.Jsr286Dispatcher</em></strong> as the portlet class in your portlet.xml file:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>portlet.xml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;portlet-app id="my-portlet-app"
	xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
	xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"&gt;

    &lt;portlet id="MyPortlet"&gt;
        &lt;description xml:lang="EN"&gt;My Portlet&lt;/description&gt;
        &lt;portlet-name&gt;MyPortlet&lt;/portlet-name&gt;
        &lt;display-name xml:lang="EN"&gt;my-portlet&lt;/display-name&gt;
    
        &lt;portlet-class&gt;org.apache.struts2.portlet.dispatcher.Jsr286Dispatcher&lt;/portlet-class&gt;
        
        &lt;!-- SNIP --&gt;

    &lt;/portlet&gt;
&lt;/portlet-app&gt;
</pre>
</div></div><h2 id="PortletPlugin-PortletInitParameters">Portlet Init Parameters</h2><p>Below is the init-param elements that you can set up in <em>portlet.xml</em> for configuring the portlet mode -&gt; xwork namespace mappings for the portlet. Basically, you can think of the different portlet modes as different sub-applications, so it can be useful to set up the <code>struts.xml</code> configuration with different namespaces for the different portlets and modes:</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Key</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>portletNamespace</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The namespace for the portlet in the action configuration. This namespace is prepended to all action lookups, and makes it possible to host multiple portlets in the same portlet application. If this parameter is set, the complete namespace will be <em>/portletNamespace/modeNamespace/actionName</em></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The default namespace.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>viewNamespace</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The namespace in the xwork config for the view portlet mode.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The default namespace.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>editNamespace</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The namespace in the xwork config for the edit portlet mode.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The default namespace.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>helpNamespace</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The namespace in the xwork config for the help portlet mode.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The default namespace.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>defaultViewAction</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Name of the action to use as default for the view portlet mode, when no action name is present.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>default</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>defaultEditAction</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Name of the action to use as default for the edit portlet mode, when no action name is present.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>default</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>defaultHelpAction</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Name of the action to use as default for the help portlet mode, when no action name is present.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>default</p></td></tr></tbody></table></div><p>e.g.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>portlet.xml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">&lt;init-param&gt;
    &lt;!-- Portlet namespace --&gt;
    &lt;name&gt;portletNamespace&lt;/name&gt;
    &lt;value&gt;/portletA&lt;/value&gt;
&lt;/init-param&gt;
&lt;init-param&gt;
    &lt;!-- The base namespace of the view portlet mode --&gt;
    &lt;name&gt;viewNamespace&lt;/name&gt;
    &lt;value&gt;/view&lt;/value&gt;
&lt;/init-param&gt;
&lt;init-param&gt;
    &lt;!-- The default action to invoke in view mode --&gt;
    &lt;name&gt;defaultViewAction&lt;/name&gt;
    &lt;value&gt;index&lt;/value&gt;
&lt;/init-param&gt;
</pre>
</div></div><p>This snippet from <code>portlet.xml</code> will set up the portlet with a namespace of <em>/portletA/. This means that all requests to this portlet will get the namespace prepended when looking up the action. In addition, the _view</em> portlet mode will map to the <em>/view</em> namespace, so a request for action <code>myAction</code> will resolve to the namespace and action <em>/portletA/view/myAction</em>. It also means that if no action is requested, the default action of <code>index</code> will be used for the request.</p><h2 id="PortletPlugin-web.xml">web.xml</h2><p>If you want to access to expose the value stack through request attributes (e.g. if you want to use regular JSTL tags to access values in the stack), you have to configure the dispatcher servlet in your web application descriptor:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>web.xml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">&lt;servlet id="Struts2PortletDispatcherServlet"&gt;
    &lt;servlet-name&gt;Struts2PortletDispatcherServlet&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.apache.struts2.portlet.dispatcher.DispatcherServlet&lt;/servlet-class&gt;
&lt;/servlet&gt;
</pre>
</div></div><div class="confluence-information-macro confluence-information-macro-note"><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p><strong>If you're only using Struts 2 tags, configuring the dispatcher servlet is optional</strong></p></div></div><h2 id="PortletPlugin-PortletPhases">Portlet Phases</h2><p>The portlet specification describes that a portlet request cycle can consist of two phases, an <em>event</em> phase and a <em>render</em> phase. In case of an <em>event</em> in the portlet, it will always execute before the <em>render</em> phase. The <em>event</em> phase is typically for changing the state of the application. In a portlet, this is typically when a form is submitted. The <em>render</em> phase will then prepare and dispatch to the view. It's recommended that you set up the result from an action that is executed in the <em>event</em> phase to point to another action that is executed in the <em>render</em> phase, which again is responsible for dispatching to the actual view.</p><h2 id="PortletPlugin-PortletResultDispatching">Portlet Result Dispatching</h2><p>The <em>struts-portlet-default</em> package defines a special default Result Type, which is responsible for performing the result logic of an Action execution. Typically, this involves including a JSP for rendering, or preparing a render action if one is configured for the current event action.</p><p>This result type has three main modes of execution.</p><ul><li>If the Action is executed in the render phase, it will perform a PortletRequestDispatcher.include(req, res) to the resource specified in the <em>location</em> attribute.</li><li>If the Action is executed in the event phase, and the result is an action mapping, it will set a render parameter on the ActionResponse to indicate which Action should be executed in the render phase. This follows good web application design, which promotes the use of a redirect after an event, which in this case means that an Action executed in the event phase will be followed by a redirect to an Action executed in the render phase.</li><li>If the Action is executed in the event phase, and the result is not an action mapping, the result will prepare a special Action called "renderDirect" (specified in the <em>struts-portlet-default</em> package) whose sole purpose is to render the specified web resource (usually a JSP).</li></ul><h3 id="PortletPlugin-redirectAction">redirectAction</h3><p>The action executed in event mode can pass render parameters to the next action to execute in render mode through parameters using the <em>redirectAction</em> result type:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>struts.xml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">&lt;result type="redirectAction" name="success"&gt;
    &lt;param name="actionName"&gt;displayCart&lt;/param&gt;
    &lt;param name="userId"&gt;${userId}&lt;/param&gt;  
    &lt;!-- If you want to redirect to a different portlet mode, use the portletMode parameter 
    &lt;param name="portletMode"&gt;view&lt;/param&gt;
    --&gt;
&lt;/result&gt;
</pre>
</div></div><p>This will set up a <em>render parameter</em> called <em>userId</em> with the value of the <em>userId</em> property on the value stack.</p><p>You can also use the <em>portletMode</em> parameter to change to a different portlet mode.</p><h2 id="PortletPlugin-s:urlands:formtags">s:url and s:form tags</h2><p>URLs in a portlet is handled quite different than for a regular web application. There's no such thing as "extension", there's simply an action name and a namespace, and they have to be specified using the respective tag attributes. URLs using the <em>value</em> attribute will be encoded as a resource URL and is only suitable for additional resources such as images and style sheets.</p><p>Example:</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Servlet</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Portlet</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>&lt;s:url value="hello.action"/&gt;</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>&lt;s:url action="hello"/&gt;</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>&lt;s:url value="style.css"/&gt;</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>&lt;s:url value="style.css"/&gt;</p></td></tr></tbody></table></div><p>In addition, there are some additional tag attributes that are portlet specific. These are:</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>portletMode</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The resulting portlet mode of the url</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>windowState</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The resulting window state of the url</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>portletUrlType</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Specifies if this is a <em>render</em> or an <em>action</em> url</p></td></tr></tbody></table></div><p>Typical usage for the <em>portletUrlType</em> is if you have a <em>delete</em> link that removes something from a database. To ensure this is done in the event phase, as recommended by the portlet specification (since it is a change of state), the url can use this attribute, e.g. &lt;s:url action="deleteEntry" portletUrlType="action"/&gt;</p><h2 id="PortletPlugin-Security">Security</h2><p><span style="color: rgb(34,34,34);">Basically the Struts2 Portlet Plugin doesn't support different auth&#160;</span><span style="color: rgb(34,34,34);">level in the same portlet. If you want to achieve that you must create&#160;</span><span style="color: rgb(34,34,34);">two separated portlets and configure access level with portlet engine&#160;</span><span style="color: rgb(34,34,34);">for each of them.</span></p><h2 id="PortletPlugin-Otherresources">Other resources</h2><p><a shape="rect" href="struts-2-portlet-tutorial.html">Struts 2 Portlet Tutorial</a><br clear="none"> <a shape="rect" class="external-link" href="http://jcp.org/aboutJava/communityprocess/final/jsr168/index.html" rel="nofollow">JSR168 Specification</a><br clear="none"> <a shape="rect" class="external-link" href="http://jcp.org/aboutJava/communityprocess/final/jsr286/index.html" rel="nofollow">JSR286 Specification</a></p></div>
        </div>

                    <div class="tabletitle">
                Children
            <span class="smalltext" id="show" style="display: inline;">
              <a href="javascript:showChildren()">Show Children</a></span>
            <span class="smalltext" id="hide" style="display: none;">
              <a href="javascript:hideChildren()">Hide Children</a></span>
            </div>
            <div class="greybox" id="children" style="display: none;">
                                                    $page.link($child)
                    <span class="smalltext">(Apache Struts 2 Documentation)</span>
                    <br>
                            </div>
        
    </div>
</div>
<div class="footer">
    Generated by CXF SiteExporter
</div>
</body>
</html>
